## Tweet-level retweets by topic regression
# Nora Webb Williams

#library(tidyverse)
library(ggplot2)
library(readr)
library(dplyr)
library(modelr)
library(stargazer)
library(plm)
library(margins)
library(lubridate)
require(stringr)
library(forcats)
library(tibble)

# read in the data
master <- read_csv("results-data/tweets_with_topic_probs.csv", 
                   col_types = cols(.default = col_character(),
                                    num_followers = col_integer(),
                                    initial_retweets = col_integer(),
                                    initial_favorites = col_integer(),
                                    delayed_retweets = col_integer(),
                                    delayed_favorites = col_double(),
                                    images_list = col_character(),
                                    video_id = col_character(),
                                    X1 = col_integer(),
                                    name = col_character(),
                                    tweet_text = col_character(),
                                   # is_valid = col_character(),
                                    gun_control = col_integer(),
                                    simple_date = col_date(format = ""),
                                    `Gun Rights` = col_character(),
                                    Incredulity = col_character(),
                                    meta_youth_leadership = col_character(),
                                    `Pride Brunch` = col_character()
                   ))

# Smallest number of followers
fewest_followers = min(master$num_followers)

# Most followers
most_followers = max(master$num_followers)


# Replace the NAs with zero for the topic probabilities
formatted <- master %>% 
  mutate(assault_weap_dum = if_else(is.na(`Assault Weapons`), 0, 1),
         back_checks_dum = if_else(is.na(`Background Checks`), 0, 1),
         gun_free_dum = if_else(is.na(`Gun Free Zones`), 0, 1),
         gun_rights_dum = if_else(is.na(`Gun Rights`), 0, 1),
         #incredulity_dum = if_else(is.na(`Incredulity`), 0, 1),
         mental_health_dum = if_else(is.na(`Mental Health`), 0, 1),
         gun_control_dum = if_else(is.na(`Gun Control`), 0, 1),
         gun_violence_dum = if_else(is.na(`Gun Violence`), 0, 1),
         enforce_fail_dum = if_else(is.na(`Enforcement Failure`), 0, 1),
         polit_act_dum = if_else(is.na(`Political Action`), 0, 1),
         #youth_leader_dum = if_else(is.na(`meta_youth_leadership`), 0, 1),
         #pride_brunch_dum = if_else(is.na(`Pride Brunch`), 0, 1),
         remembrance_dum = if_else(is.na(`Remembrances`), 0, 1),
         school_security_dum = if_else(is.na(`School Security`), 0, 1),
         school_shooting_dum = if_else(is.na(`School Shootings`), 0, 1)) %>% 
  mutate(image_dum = if_else(is.na(images_list), 0, 1)) %>% 
  unique()

## What is the distribution of retweets?
p <- ggplot(formatted, aes(x=initial_retweets)) + 
  geom_density() +
  geom_vline(aes(xintercept=mean(initial_retweets)),
                             color="blue", linetype="dashed", size=1) +
  theme_bw()

#Yeah, that's zero inflated...
#print(p)


######## Modeling
# Simple ols
model1 <- initial_retweets ~  num_followers + 
  gun_control + 
  image_dum + 
  assault_weap_dum + 
  back_checks_dum + 
  gun_free_dum +
  gun_rights_dum + 
  #incredulity_dum + 
  mental_health_dum + 
  gun_control_dum + 
  gun_violence_dum +
  enforce_fail_dum +  
  polit_act_dum + 
  #youth_leader_dum + 
  #pride_brunch_dum + 
  remembrance_dum +
  school_security_dum + 
  school_shooting_dum
         

ols_reg1 <- lm(model1, data = formatted )         
summary(ols_reg1)
         
#stargazer(ols_reg1, single.row = T)

# With hack-y fixed effects
model1_fe <- initial_retweets ~  num_followers + 
  gun_control + 
  image_dum + 
  assault_weap_dum + 
  back_checks_dum + 
  gun_free_dum +
  gun_rights_dum + 
  #incredulity_dum + 
  mental_health_dum + 
  gun_control_dum + 
  gun_violence_dum +
  enforce_fail_dum +  
  polit_act_dum + 
  #youth_leader_dum + 
  #pride_brunch_dum + 
  remembrance_dum +
  school_security_dum + 
  school_shooting_dum +
  as.factor(name)
         
ols_reg1_fe <- lm(model1_fe, data = formatted )         
summary(ols_reg1_fe)

# Interacting gun position and key topics
model2 <- initial_retweets ~  num_followers + 
  gun_control + 
  image_dum + 
  gun_control*image_dum +
  assault_weap_dum + 
  gun_control*assault_weap_dum + 
  back_checks_dum + 
  gun_control*back_checks_dum + 
  gun_free_dum +
  gun_control*gun_free_dum +
  gun_rights_dum + 
  # gun_control*gun_rights_dum + 
  mental_health_dum + 
  gun_control*mental_health_dum + 
  gun_control_dum + 
  gun_control*gun_control_dum + 
  gun_violence_dum +
  gun_control*gun_violence_dum +
  enforce_fail_dum +
  gun_control*enforce_fail_dum + 
  polit_act_dum + 
  gun_control*polit_act_dum +
  #youth_leader_dum + 
  # gun_control*youth_leader_dum + 
  #pride_brunch_dum + 
  # gun_control*pride_brunch_dum + 
  remembrance_dum +
  gun_control*remembrance_dum +
  school_security_dum + 
  gun_control*school_security_dum + 
  school_shooting_dum
  #gun_control*school_shooting_dum

ols_reg2 <- lm(model2, data = formatted )         
summary(ols_reg2)


# Interactions and hacky fe
model2_fe <- initial_retweets ~  num_followers + 
  gun_control + 
  image_dum + 
  gun_control*image_dum +
  assault_weap_dum + 
  gun_control*assault_weap_dum + 
  back_checks_dum + 
  gun_control*back_checks_dum + 
  gun_free_dum +
  gun_control*gun_free_dum +
  gun_rights_dum + 
  # gun_control*gun_rights_dum + 
  mental_health_dum + 
  gun_control*mental_health_dum + 
  gun_control_dum + 
  gun_control*gun_control_dum + 
  gun_violence_dum +
  gun_control*gun_violence_dum +
  enforce_fail_dum +
  gun_control*enforce_fail_dum + 
  polit_act_dum + 
  gun_control*polit_act_dum +
  #youth_leader_dum + 
  # gun_control*youth_leader_dum + 
  #pride_brunch_dum + 
  # gun_control*pride_brunch_dum + 
  remembrance_dum +
  gun_control*remembrance_dum +
  school_security_dum + 
  gun_control*school_security_dum + 
  school_shooting_dum +
  #gun_control*school_shooting_dum
  as.factor(name)

ols_reg2_fe <- lm(model2_fe, data = formatted )         
summary(ols_reg2_fe)

# no fe table
stargazer(ols_reg1, ols_reg2, single.row = T)

# fe table (manually leave off the fe)
stargazer(ols_reg1_fe, ols_reg2_fe, single.row = T)

# full table (manualy leave off the fe)
stargazer(ols_reg1, ols_reg1_fe, ols_reg2, ols_reg2_fe, single.row = T)


############# Models with only after Parkland data
# Save the parkland dates
prkland <- make_date(year = 2018, month = 2, day = 14)
prkland_dt <- as_datetime(prkland) %>% 
  force_tz(prkland_dt, tzone = "America/New_York") # in the right time zone


formatted_postpkld <- formatted %>% 
  filter(tweet_dayfloor >= prkland) %>% 
  unique()

# How many RTs on average for a given tweet in the data?
mean(formatted_postpkld$initial_retweets)
max(formatted_postpkld$initial_retweets)
min(formatted_postpkld$initial_retweets)

# Rerun with limited data
ols_reg1_postpkld <- lm(model1, data = formatted_postpkld )         
summary(ols_reg1_postpkld)

ols_reg1_postpkld_fe <- lm(model1_fe, data = formatted_postpkld)         
summary(ols_reg1_postpkld_fe)

ols_reg2_postpkld <- lm(model2, data = formatted_postpkld)         
summary(ols_reg2_postpkld)

ols_reg2_postpkld_fe <- lm(model2_fe, data = formatted_postpkld)         
summary(ols_reg2_postpkld_fe)

### TABLE 8 in PAPER
# full table (manualy leave off the fe)
stargazer(ols_reg1_postpkld, ols_reg1_postpkld_fe, 
          ols_reg2_postpkld, ols_reg2_postpkld_fe, single.row = T)


#####################
# Plot
###### With the limited data
# Takes a while to run!
#ols_reg2_postpkld_fe_margins <- margins(ols_reg2_postpkld_fe)
#summary(ols_reg2_postpkld_fe_margins)


# Find the margins at different levels of gun_control
ols_reg2_postpkld_fe_margins_gun_levels <- margins(ols_reg2_postpkld_fe, 
                                                   at = list(gun_control = range(formatted$gun_control)))

plot(ols_reg2_postpkld_fe_margins_gun_levels)

### hm, se is not coming out correctly
summary(ols_reg2_postpkld_fe_margins_gun_levels)

gun_levels_me_postpkld <-as_tibble(summary(ols_reg2_postpkld_fe_margins_gun_levels))


frame_names <- c("Enforcement Failure",
                 "Mental Health",
                 "School Security",
                 "Gun Free Zones",
                 "Assault Weapons",
                 "Gun Control",
                 "Background Checks",
                 "Political Action")

gun_levels_topics_only_postpkld <- gun_levels_me_postpkld %>% 
  filter(str_detect(factor, "_dum")) %>% 
  mutate(factor = str_replace(factor, "_dum", ""),
         factor = str_replace(factor, "_", " "),
         factor = str_to_title(factor),
         factor = replace(factor, factor == "Enforce Fail", "Enforcement Failure"),
         factor = replace(factor, factor == "Assault Weap", "Assault Weapons"),
         factor = replace(factor, factor == "Back Checks", "Background Checks"),
         factor = replace(factor, factor == "Polit Act", "Political Action"),
         factor = replace(factor, factor == "Gun Free", "Gun Free Zones"),
         factor = replace(factor, factor == "Youth Leader", "Youth Leadership"),
         factor = replace(factor, factor == "Image", "Contains Image"),
         factor = replace(factor, factor == "School Shooting", "School Shootings"),
         factor = replace(factor, factor == "Remembrance", "Remembrances")) %>% 
  mutate(gun_control_str = if_else(gun_control == 1, "Gun Control", "Gun Rights")) %>% 
  filter(factor %in% frame_names)

# Plot it 
# Figure 5 in paper

ggplot(data = gun_levels_topics_only_postpkld, aes(x = fct_reorder(factor, AME), y = AME)) +
  geom_hline(aes(yintercept = 0), color = "gray",
             linetype = 2, size = 0.5) +
  geom_point(aes(color = gun_control_str)) +
  geom_errorbar(aes(min = lower, max = upper, 
                    color = gun_control_str, 
                    linetype = gun_control_str)) +
  ylab("Marginal Effect on Retweets \n of Adding a Given Topic") +
  xlab("Frame") +
  labs(color= 'Gun Position', linetype = 'Gun Position') +
  scale_color_manual(values=c("#56B4E9", "#E69F00")) +
  theme_classic() +
  theme(axis.title.x = element_text(size=18),
        axis.text.x  = element_text(size=16),
        axis.title.y = element_text(size=18),
        axis.text.y  = element_text(size=16),
        plot.title = element_text(size = 18),
        legend.title = element_text(size=16),
        legend.text = element_text(size=14)) +
  coord_flip()

ggsave("results-figures/margins_postpkld_topics_on_rts.png")
ggsave("results-figures/margins_postpkld_topics_on_rts.pdf")


### Non post-Parkland model
### Showing the predictions
# Grid based on the OLS FE with interaction

# Using the new margins package

# ols_reg2_fe is the result we care about

# Takes a while to run!
#ols_reg2_fe_margins <- margins(ols_reg2_fe)
#summary(ols_reg2_fe_margins)


# Find the margins at different levels of gun_control
ols_reg2_fe_margins_gun_levels <- margins(ols_reg2_fe, at = list(gun_control = range(formatted$gun_control)))

require(stringr)

gun_levels_me <-as.tibble(summary(ols_reg2_fe_margins_gun_levels))

gun_levels_topics_only <- gun_levels_me %>% 
  filter(str_detect(factor, "_dum")) %>% 
  mutate(factor = str_replace(factor, "_dum", ""),
         factor = str_replace(factor, "_", " "),
         factor = str_to_title(factor),
         factor = replace(factor, factor == "Enforce Fail", "Enforcement Failure"),
         factor = replace(factor, factor == "Assault Weap", "Assault Weapons"),
         factor = replace(factor, factor == "Back Checks", "Background Checks"),
         factor = replace(factor, factor == "Polit Act", "Political Activism")) %>% 
  mutate(gun_control_str = if_else(gun_control == 1, "Gun Control", "Gun Rights"))

# Plot it 
require(forcats)
ggplot(data = gun_levels_topics_only, aes(x = fct_reorder(factor, AME), y = AME)) +
  geom_hline(aes(yintercept = 0), color = "gray",
             linetype = 2, size = 0.5) +
  geom_point(aes(color = gun_control_str)) +
  geom_errorbar(aes(min = lower, max = upper, 
                    color = gun_control_str, 
                    linetype = gun_control_str)) +
  ylab("Marginal Effect on RTs of Adding a Given Topic") +
  xlab("Topic") +
  labs(color= 'Gun Position', linetype = 'Gun Position') +
  scale_color_manual(values=c("#56B4E9", "#E69F00")) +
  theme_bw() +
  coord_flip()

ggsave("results-figures/margins_topics_on_rts.png")
ggsave("results-figures/margins_topics_on_rts.pdf")


###########################
##### DEPRECATED, but a check on margins package
# Panel approach
# Took out the time aspect for the index... 
panel_data <- pdata.frame(formatted, index=c("name"), drop.index=TRUE, row.names=TRUE)
panel_data <- unique(panel_data) # drop duplicates

# Replicate the raw ols results with plm package
panel_reg1 <- plm(model1, data = panel_data, model = "pooling")
summary(panel_reg1)


# Trying to replicate the ols results with org FE with plm package
# Getting different results! might be because drops the gun_control variable...
panel_reg2 <- plm(model1, data = panel_data, model = "within")
summary(panel_reg2)
# Look at the fixed effects:
summary(fixef(panel_reg2, type = 'dmean'))

# Random effects
# Doesn't work
panel_reg3 <- plm(model1, data = panel_data, model = "random")
summary(panel_reg3)


###########################
##### DEPRECATED, but a check on margins package
# Never got loop working
## loop over all of the topics? 

# topics of interest
topics = list("image_dum", 
            #  "assault_weap_dum", # already done
              "back_checks_dum",
              "gun_free_dum",
              "gun_rights_dum",
              "mental_health_dum",
              "gun_control_dum",
              "gun_violence_dum",
              "polit_act_dum",
              "youth_leader_dum",
              "pride_brunch_dum",
              "remembrance_dum",
              "school_security_dum",
              "school_shooting_dum")

# Pulling a neeeded value
median_followers <- median(master$num_followers)

#### YEAh, this isn't working....

for (i in seq_along(topics)){
  
  print(str_c("Generating ME for ", topics[[i]]))

  preds_for_this_topic <- formatted %>% 
    data_grid(name, gun_control, !! quoted, 
              num_followers = median_followers, .model = ols_reg2_fe) %>%
    add_predictions(ols_reg2_fe) %>% 
    spread(key = !! topics[[i]], value = pred) %>%
    rename(yes_this_topic = `1`,
           no_this_topic = `0`) %>% 
    mutate(!! topics[[i]] = yes_enforce_fail - no_enforce_fail) %>% 
    group_by(gun_control) %>% 
    slice(1) %>% 
    select(gun_control, !! topics[[i]])
  
  
}  

### one by one!

# image_dum 
image_dum_preds <- formatted %>% 
  data_grid(name, gun_control, image_dum, 
          num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = image_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_image_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_image_dum)

# Something to merge with
master_preds <- image_dum_preds

### ME of enforcement failure narrative

enforce_fail_preds <- formatted %>% 
  data_grid(name, gun_control, enforce_fail_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = enforce_fail_dum, value = pred) %>% 
  rename(yes_enforce_fail = `1`,
         no_enforce_fail = `0`) %>% 
  mutate(me_enforce_fail = yes_enforce_fail - no_enforce_fail) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_enforce_fail)


# Join it
master_preds <- left_join(master_preds, enforce_fail_preds, by = "gun_control")

#########
back_checks_dum_preds <- formatted %>% 
  data_grid(name, gun_control, back_checks_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = back_checks_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_back_checks_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_back_checks_dum)

# Join it
master_preds <- left_join(master_preds, back_checks_dum_preds, by = "gun_control")

#########
gun_free_dum_preds <- formatted %>% 
  data_grid(name, gun_control, gun_free_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = gun_free_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_gun_free_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_gun_free_dum)

# Join it
master_preds <- left_join(master_preds, gun_free_dum_preds, by = "gun_control")


#########
gun_rights_dum_preds <- formatted %>% 
  data_grid(name, gun_control, gun_rights_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = gun_rights_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_gun_rights_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_gun_rights_dum)

# Join it
master_preds <- left_join(master_preds, gun_rights_dum_preds, by = "gun_control")

#########
mental_health_dum_preds <- formatted %>% 
  data_grid(name, gun_control, mental_health_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = mental_health_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_mental_health_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_mental_health_dum)

# Join it
master_preds <- left_join(master_preds, mental_health_dum_preds, by = "gun_control")
     
#########
gun_control_dum_preds <- formatted %>% 
  data_grid(name, gun_control, gun_control_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = gun_control_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_gun_control_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_gun_control_dum)

# Join it
master_preds <- left_join(master_preds, gun_control_dum_preds, by = "gun_control")

#########
gun_violence_dum_preds <- formatted %>% 
  data_grid(name, gun_control, gun_violence_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = gun_violence_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_gun_violence_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_gun_violence_dum)

# Join it
master_preds <- left_join(master_preds, gun_violence_dum_preds, by = "gun_control")


#########
polit_act_dum_preds <- formatted %>% 
  data_grid(name, gun_control, polit_act_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = polit_act_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_polit_act_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_polit_act_dum)

# Join it
master_preds <- left_join(master_preds, polit_act_dum_preds, by = "gun_control")

#########
youth_leader_dum_preds <- formatted %>% 
  data_grid(name, gun_control, youth_leader_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = youth_leader_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_youth_leader_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_youth_leader_dum)

# Join it
master_preds <- left_join(master_preds, youth_leader_dum_preds, by = "gun_control")

#########
pride_brunch_dum_preds <- formatted %>% 
  data_grid(name, gun_control, pride_brunch_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = pride_brunch_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_pride_brunch_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_pride_brunch_dum)

# Join it
master_preds <- left_join(master_preds, pride_brunch_dum_preds, by = "gun_control")

#########
remembrance_dum_preds <- formatted %>% 
  data_grid(name, gun_control, remembrance_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = remembrance_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_remembrance_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_remembrance_dum)

# Join it
master_preds <- left_join(master_preds, remembrance_dum_preds, by = "gun_control")

#########
school_security_dum_preds <- formatted %>% 
  data_grid(name, gun_control, school_security_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = school_security_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_school_security_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_school_security_dum)

# Join it
master_preds <- left_join(master_preds, school_security_dum_preds, by = "gun_control")


#########
school_shooting_dum_preds <- formatted %>% 
  data_grid(name, gun_control, school_shooting_dum, 
            num_followers = median(master$num_followers), .model = ols_reg2_fe) %>%
  add_predictions(ols_reg2_fe) %>% 
  spread(key = school_shooting_dum, value = pred) %>% 
  rename(yes_this_topic = `1`,
         no_this_topic = `0`) %>% 
  mutate(me_school_shooting_dum = yes_this_topic - no_this_topic) %>% 
  group_by(gun_control) %>% 
  slice(1) %>% 
  select(gun_control, me_school_shooting_dum)

# Join it
master_preds <- left_join(master_preds, school_shooting_dum_preds, by = "gun_control")


## Reshape the preds
preds_gather <- master_preds %>% 
  gather(me_image_dum:me_school_shooting_dum, key = topic, value = pred) %>% 
  mutate(topic_name = str_replace(topic, "me_", ""),
         topic_name = str_replace(topic_name, "_dum", ""),
         topic_name = as.factor(topic_name)) 
  

## plot it?
ggplot(data = preds_gather, aes(x = fct_reorder(topic_name, pred), y = pred)) +
  geom_point(aes(color = as.factor(gun_control))) +
  ylab("Marginal Effect on RTs of Adding a Given Topic") +
  xlab("Topic") +
  theme_bw() +
  coord_flip()

ggsave("results-figures/me_topics_on_rts.png")
ggsave("results-figures/me_topics_on_rts.pdf")


